import {createRouter, createWebHashHistory} from "vue-router";
import type {RouteRecordRaw} from "vue-router";
import {setting} from "@/setting";

let routes: RouteRecordRaw[] = [
    {
        path: "/",
        component: () => import("@/pages/main/index.vue"),
        name: "main",
        meta: {
            title: "首页",
        },
    },
];

const {components, lowCode, dataWorks} = setting;

//组件库组件路由注入
_.forEach(components, (item) => {
    //测试页面
    routes.push({
        path: `/${item.name}`,
        component: () => import(`@/pages/examples/library/${item.name}/index.vue`),
        name: item.name,
        meta: {
            title: item.name,
        },
    });
    //API页面
    routes.push({
        path: `/api/library/${item.name}`,
        component: () => import(`@/pages/api/library/${item.name}/index.vue`),
        name: `${item.name}api`,
        meta: {
            title: `${item.name}api`,
        },
    });
});

//低代码组件库组件路由注入
_.forEach(lowCode, (item) => {
    //测试页面
    routes.push({
        path: `/lowCode/${item.name}`,
        component: () => import(`@/pages/examples/lowCode/${item.name}/index.vue`),
        name: item.name,
        meta: {
            title: item.name,
        },
    });
    //API页面
    routes.push({
        path: `/api/lowCode/${item.name}`,
        component: () => import(`@/pages/api/lowCode/${item.name}/index.vue`),
        name: `${item.name}api`,
        meta: {
            title: `${item.name}api`,
        },
    });
});

//数据大屏组件库组件路由注入
_.forEach(dataWorks, (item) => {
    //测试页面
    routes.push({
        path: `/dataWorks/${item.name}`,
        component: () => import(`@/pages/examples/dataWorks/${item.name}/index.vue`),
        name: item.name,
        meta: {
            title: item.name,
        },
    });
});

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach(async (to, from, next) => {
    next();
});
export default router;
